package com.usian.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author chen
 * @date 2021/2/3 - 23:03 - 星期三
 * @project usian_parent
 * @package com.usian.config
 * @by GGbomd猪猪侠
 */
@Configuration //表明这是一个配置类
@EnableSwagger2 //开启Swagger2
public class SwaggerConfig {

    @Bean
    public Docket api(){ //Docket：生成接口文档
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .select()
                //基于com.usian.controller生成api文档
                .apis(RequestHandlerSelectors.basePackage("com.usian.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo getApiInfo(){
        return new ApiInfoBuilder()
                .title("忧思安商城后台管理系统") //标题
                .description("商品管理模块接口文档") //描述
                .version("1.0") //版本
                .build();
    }
}
